{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "125979b1",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2740244147.py, line 33)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[4], line 33\u001b[1;36m\u001b[0m\n\u001b[1;33m    elif 用户选择 == \"quit\":\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 1\n",
    "alipay = input(\"请输入余额:\") # 用户输入\n",
    "\n",
    "\n",
    "商品列表 = [[\"iPhone15\",8999],[\"mate60 Pro\",6999],[\"锐克5代(丁真同款)\",200],[\"游戏\",49]]\n",
    "    \n",
    "\n",
    "# print(商品列表)    \n",
    "print(\"------------Lck NEVER GIVE UP(注： 输入 quit 退出购买------------\")\n",
    "for i in 商品列表:\n",
    "        print(\"商品编号:%s,商品名称: %s,价格为: %s元\"%(商品列表.index(i),i[0],i[1]))\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    # 2 用户选择\n",
    "用户选择 = int(input(\"用户选择的商品编号:\"))\n",
    "if 用户选择.isdigit():\n",
    "    用户选择=int(用户选择)\n",
    "    # 增加进购物车，扣钱\n",
    "\n",
    "    # print(商品列表[int(用户选择)][1],type(商品列表[用户选择][1]))\n",
    "\n",
    "if alipay > 商品列表[用户选择][1]:\n",
    "    #1. 钱够扣钱，加入购物车\n",
    "    alipay = alipay - 商品列表[用户选择][1]\n",
    "    shopping_car.append(商品列表[用户选择])\n",
    "    print(\"您的余额为：%s 元\"%(alipay,商品列表[用户选择][0]))\n",
    "       \n",
    "else:\n",
    "    print(\"您的余额不足，无法购买%s\"%(alipay,商品列表[用户选择][0]))\n",
    "    elif 用户选择 == \"quit\":\n",
    "        print(\"感谢光顾小店，欢迎下次光临\")\n",
    "        break\n",
    "        else:\n",
    "            print(\"请输入正确的商品编号 或 输入'quit' 退出小店\")\n",
    "\n",
    "print(\"购物车\",shopping_car)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b796fb8e",
   "metadata": {},
   "source": [
    "> index 其实就是检索列表，一个逗号算作一个元素 使用for循环的时候用什么字母去代替那个元素，最终print的结果都是那个元素"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb73035c",
   "metadata": {},
   "source": [
    ">>1.<font style=\"color:red\">用户输入input的结果必然是字符串 str</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f421ea5b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27ec3a42",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
